﻿using System.Collections.Generic;
using LiteNetLib.Utils;
using FrameOperateSync;

public static class SyncDataPackageUtil
{
    //public static void DeserializePackage(NetDataReader reader, in ServerKeyFramePackage package)
    //{
    //    package.alignKeyframeIndex = reader.GetInt();
    //    var count = reader.GetInt();
    //    package.playerPackageList = new List<KeyFramePackage>(count);
    //    for (int i = 0; i < count; i++)
    //    {
    //        DeserializeToKeyFramePackage(reader, out var keyPackage);
    //        package.playerPackageList.Add(keyPackage);
    //    }
    //}
    //public static void SerializePackage(NetDataWriter writer, ServerKeyFramePackage package)
    //{
    //    writer.Reset();
    //    writer.Put(package.alignKeyframeIndex);
    //    writer.Put(package.playerPackageList != null ? package.playerPackageList.Count : 0);
    //    if(package.playerPackageList != null && package.playerPackageList.Count != 0)
    //    {
    //        foreach(var pp in package.playerPackageList)
    //        {
    //            SerializePackage(writer, pp);
    //        }
    //    }
    //}
    //public static void SerializePackage(NetDataWriter writer, KeyFramePackage package)
    //{
    //    writer.Put(package.bagOrderId);
    //    writer.Put(package.sendPackageTicks);
    //    var count = package.playerSyncDataList.Count;
    //    writer.Put(count);
    //    foreach (var data in package.playerSyncDataList)
    //    {
    //        Serialize(writer, data);
    //    }
    //}

    //public static void DeserializeToKeyFramePackage(NetDataReader reader, out KeyFramePackage data)
    //{
    //    data = KeyFramePackage.Create();
    //    data.bagOrderId = reader.GetInt();
    //    data.sendPackageTicks = reader.GetLong();
    //    var count = reader.GetInt();
    //    data.playerSyncDataList = new List<FrameOperateData>(count);
    //    for(int i = 0;i<count;i++)
    //    {
    //        Deserialize(reader, out var op);
    //        data.playerSyncDataList.Add(op);
    //    }

    //}

    //public static void Deserialize(NetDataReader reader, out FrameOperateData data)
    //{
    //    data = new FrameOperateData()
    //    {
    //        FrameIndex = reader.GetInt(),
    //        LogicCode = reader.GetInt(),
    //        PlayerId = reader.GetInt(),
    //        bornTicks = reader.GetLong(),
    //    };
    //    try
    //    {
    //        data.Data = data.LogicCode == -1 ? null : reader.GetBytesWithLength();
    //    }catch(System.OverflowException e)
    //    {
    //        UnityEngine.Debug.LogError($"致命错误,解析数据时益处，logiccode:{data.LogicCode}，playerid:{data.PlayerId},frameIndex:{data.FrameIndex}");
    //        throw;
    //    }
    //}

    //public static void Serialize(NetDataWriter writer, FrameOperateData data)
    //{
    //    writer.Put(data.FrameIndex);
    //    writer.Put(data.LogicCode);
    //    writer.Put(data.PlayerId);
    //    writer.Put(data.bornTicks);
    //    if (data.LogicCode != -1)
    //    {
    //        writer.PutBytesWithLength(data.Data, 0, data.Data.Length);
    //    }
    //}
}

